//// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
//package com.linqingying.gitcode.pullrequest.ui.review
//
//import com.intellij.collaboration.messages.CollaborationToolsBundle
//import com.intellij.collaboration.ui.HorizontalListPanel
//import com.intellij.collaboration.ui.codereview.list.error.ErrorStatusPresenter
//import com.intellij.collaboration.ui.codereview.review.CodeReviewSubmitPopupHandler
//import com.intellij.collaboration.ui.util.bindDisabledIn
//import com.intellij.collaboration.ui.util.bindVisibilityIn
//import com.intellij.ide.plugins.newui.InstallButton
//import com.intellij.openapi.ui.MessageDialogBuilder
//import com.intellij.util.ui.InlineIconButton
//import com.intellij.util.ui.JBUI
//import icons.CollaborationToolsIcons
//import kotlinx.coroutines.CoroutineScope
//import kotlinx.coroutines.flow.map
//import com.linqingying.gitcode.api.data.GCPullRequestReviewEvent
//import com.linqingying.gitcode.i18n.GitCodeBundle
//import com.linqingying.gitcode.ui.component.GCHtmlErrorPanel
//import java.awt.event.ActionListener
//import javax.swing.Action
//import javax.swing.JButton
//import javax.swing.JComponent
//import javax.swing.JPanel
//
//internal object GCPRSubmitReviewPopup : CodeReviewSubmitPopupHandler<GCPRSubmitReviewViewModel>() {
//  override fun CoroutineScope.createActionsComponent(vm: GCPRSubmitReviewViewModel): JPanel {
//    val cs = this
//    val buttons = buildList<JComponent> {
//      if (!vm.viewerIsAuthor) {
//        object : InstallButton(GitCodeBundle.message("pull.request.review.submit.approve.button"), true) {
//          override fun setTextAndSize() {}
//        }.apply {
//          bindDisabledIn(cs, vm.isBusy)
//          addActionListener { vm.submit(GCPullRequestReviewEvent.APPROVE) }
//        }.let(::add)
//
//        JButton(GitCodeBundle.message("pull.request.review.submit.request.changes")).apply {
//          isOpaque = false
//        }.apply {
//          bindDisabledIn(cs, vm.isBusy)
//          addActionListener { vm.submit(GCPullRequestReviewEvent.REQUEST_CHANGES) }
//        }.let(::add)
//      }
//
//      JButton(GitCodeBundle.message("pull.request.review.submit.comment.button")).apply {
//        isOpaque = false
//        toolTipText = GitCodeBundle.message("pull.request.review.submit.comment.description")
//      }.apply {
//        bindDisabledIn(cs, vm.isBusy)
//        addActionListener { vm.submit(GCPullRequestReviewEvent.COMMENT) }
//      }.let(::add)
//    }
//    return HorizontalListPanel(ACTIONS_GAP).apply {
//      buttons.forEach { add(it) }
//    }
//  }
//
//  override fun createTitleActionsComponentIn(cs: CoroutineScope, vm: GCPRSubmitReviewViewModel): JComponent {
//    val defaultActions = super.createTitleActionsComponentIn(cs, vm)
//    if (!vm.hasPendingReview) {
//      return defaultActions
//    }
//
//    val discardButton = InlineIconButton(
//      icon = CollaborationToolsIcons.Delete,
//      hoveredIcon = CollaborationToolsIcons.DeleteHovered,
//      tooltip = GitCodeBundle.message("pull.request.discard.pending.comments")
//    ).apply {
//      border = JBUI.Borders.empty(5)
//      bindDisabledIn(cs, vm.isBusy)
//      bindVisibilityIn(cs, vm.draftCommentsCount.map { it > 0 })
//    }.also { button ->
//      button.actionListener = ActionListener {
//        val discardButtonMessageDialog = MessageDialogBuilder.yesNo(
//          GitCodeBundle.message("pull.request.discard.pending.comments.dialog.title"),
//          GitCodeBundle.message("pull.request.discard.pending.comments.dialog.msg")
//        )
//        if (discardButtonMessageDialog.ask(button)) {
//          vm.discard()
//        }
//      }
//    }
//
//    return HorizontalListPanel(TITLE_ACTIONS_GAP).apply {
//      add(discardButton)
//      add(defaultActions)
//    }
//  }
//
//  override val errorPresenter: ErrorStatusPresenter<Throwable> by lazy {
//    object : ErrorStatusPresenter.Text<Throwable> {
//      @Deprecated(
//        "Moved to ErrorStatusPresenter.Text",
//        replaceWith = ReplaceWith(
//          "ErrorStatusPresenter.TextErrorStatusPresenter.getErrorTitle",
//          "com.intellij.collaboration.ui.codereview.list.error.ErrorStatusPresenter.Text"
//        )
//      )
//      override fun getErrorTitle(error: Throwable): String = CollaborationToolsBundle.message("review.submit.failed")
//      override fun getErrorDescription(error: Throwable): String = GCHtmlErrorPanel.getLoadingErrorText(error)
//      override fun getErrorAction(error: Throwable): Action? = null
//    }
//  }
//}
